Custom markdown
You can use custom ts-docs markdown syntax in order to make your documentation more informative and prettier. You can use this syntax in custom pages and in jsdoc comments.
References in codeblocks
If the language inside the codeblock is typescript or javascript, ts-docs will try to link every reference used in the code.
import { Generatorclass Generatorts-docs/generator/Generator } from "ts-docs";
const gen = new Generatorclass Generatorts-docs/generator/Generator({...});
gen.generate();
Code tabs
Use this if you want to provide code snippets in multiple languages, formats, styles, etc.
```ts --Typescript
function add(a: number, b: number) : number {
return a + b;
}
```
```rs --Rust
fn add(a: i32, b: i32) -> i32 {
a + b
}
```
Becomes:
Linking assets
If you want to have an image which comes from the assets
folder, simply start the link of the image with ./assets
or assets
.
Example:
[cute_kitty](./assets/images/cute_kitty.png)
Text blocks
You can create warning, note or success text blocks with the following syntax:
This is a warning!
Example:
|> This is a warning!
By default the text block is styled as a warning.
This is a note!
Example:
|>[note] This is a note!
This is a success block!
Example:
|>[success] This is a success block!
The style specifier ([note|warning|success]
) must be RIGHT after the text block start.
References
You can reference classes, interfaces, enums, type aliases, methods, properties, functions, constants, namespaces and modules by putting their name inside double square brackets, for example:
[[Generator]]
becomes Generatorclass Generatorts-docs/generator/Generator
Methods and properties
You can reference a property by adding a dot (.
) and then the name of the property.
[[Generator.structure]]
becomes Generator.structureproperty Generator.structurets-docs/generator/Generator
You can reference a method by adding a dot (.
), the method's name, and then ()
at the end.
[[Generator.generate()]]
becomes Generator.generatemethod Generator.generatets-docs/generator/Generator
If the method or property is inside the class/interface/enum you're currently writing documentation for, you can just provide their name, and ts-docs will figure out:
[[generate]]
becomes Generator.generatemethod Generator.generatets-docs/generator/Generator
By path
ts-docs searches each module in order to find the name of the references, this could lead to inaccurate links, so you always can just provide the entire path to the item.
[[extractor/extractor/TypescriptExtractor]]
becomes TypescriptExtractorclass TypescriptExtractorextractor/extractor/TypescriptExtractor
Name aliases
You can also follow up a normal reference or a reference by path with as ...
or | ...
to change the text that gets displayed.
[[Generator as TsDocsGenerator]]
becomes TsDocsGeneratorclass Generatorts-docs/generator/Generator
[[ts-docs | the documentation generator]]
becomes the documentation generatormodule ts-docsts-docs
By type
Let's say you have a class with the name ABC
, and an interface with the same name, and both of the declarations are inside the same module. If you were to search for it either by name or by path, always the item declared first will show. To prevent this, you can prefix the name with :<type>
to only search for items of the specified type and name.
[[Generator:class]]
becomes Generatorclass Generatorts-docs/generator/Generator
Available types are: class
, interface
, enum
, function
, constant
, type
, module
.
Supported JSDoc tags
@category
Groups items (class, interface, enum, type alias, function, constant) into categories, which will be shown in the sidebar.
@alpha
, @beta
, @deprecated
, @experimental
Shows the state of the API being documented.
@example
Documents an example.
/**
* @example
*
* ```ts
* const myApple = new Apple("Ambrosia");
* myApple.eat();
* ```
*
*/
class Apple {
kind: string
constructor(kind: string) {
this.kind = kind;
}
}
@internal
Omit an item from the documentation. This tag works for the following items:
- classes
- class members (methods, properties, getters, setters)
- interfaces
- interface members
- enums
- enum members
- functions
- type aliases
- constants
It doesn't work for namespaces.
You also have to enable the stripInternal
option.
@inheritDoc
Automatically generates documentation by copying it from the specified item. It copies the following things:
- The item's summary
- The item's
@remark
s - The item's
@param
s - The item's
@return
@param
Documents a method / function parameter, the parameter type WILL NOT be used by ts-docs.
/**
* @param a Parameter description...
*
*/
function doSomething(a: string) : void {
// Code...
}
@link
, @linkplain
, @linkcode
Work exactly the same as using the square bracket syntax [[]]
. Currently, @linkplain
and @linkcode
do not change the style of the reference.
@returns
, @throws
Documents information about the return value of the method, or what errors it throws.
@since
Adds a since
tag to the item that has the tag, along with a version name.